﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Linq;
using QLKetNoi;

namespace QLPhanQuyen.DAO
{
    class ChucNang_QuyenHanDAO
    {
        QLDNDataContext db = new QLDNDataContext();
        Table<CHUCNANG_QUYENHAN> cnqhs;

        public bool ThemChucNangQuyenHan(CHUCNANG_QUYENHAN CNQH)
        {
            CHUCNANG_QUYENHAN cnqh = new CHUCNANG_QUYENHAN();
            cnqh.MaChucNang = CNQH.MaChucNang;
            cnqh.MaQuyenHan = CNQH.MaQuyenHan;

            try
            {
                cnqhs.InsertOnSubmit(cnqh);
                db.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public List<string> LayQuyenHanTheoChucNang(string maChucNang)
        {
            cnqhs = db.GetTable<CHUCNANG_QUYENHAN>();

            var query = (from cq in cnqhs
                         where cq.MaChucNang == maChucNang
                         select cq.MaQuyenHan).ToList();
            return query;
        }
    }
}
